<?php
require_once "weixin_info.php";//å¾®ä¿¡æŽˆæƒèŽ·å–ç”¨æˆ·å¤´åƒç­‰ä¿¡æ?
require_once "config.php";
$id = $_GET['id'];
$type = $_GET['type'];
// echo $type;exit;
$goods_sql = $mysql->query("select * from dyspw_goods_order where id=".$id);//è§†é¢‘
$order = $goods_sql->fetch_all(MYSQLI_ASSOC);
$goods_sql = $mysql->query("select * from dyspw_goods where id=".$order[0]['goods_id']);//è§†é¢‘
$goods = $goods_sql->fetch_all(MYSQLI_ASSOC);
$shop_sql = $mysql->query("select * from dyspw_member where id=".$order[0]['u_id']);//è§†é¢‘
$shop = $shop_sql->fetch_all(MYSQLI_ASSOC);

// foreach ($order as $key => $val) {
//     $goods_sql = $mysql->query("select * from dyspw_goods where id=".$order[0]['goods_id']);//è§†é¢‘
//     $goods = $goods_sql->fetch_all(MYSQLI_ASSOC);
//     $order[$key]['title'] = $goods[0]['title'];
//     $order[$key]['details'] = $goods[0]['details'];
//     $order[$key]['money'] = $goods[0]['money'];
//     $order[$key]['img'] = $goods[0]['img'];
//
// }
 ?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>订单详情</title>
    <script src="js/mui.min.js"></script>
    <link href="css/mui.min.css" rel="stylesheet" />
    <link href="css/order.css" rel="stylesheet" />
    <script type="text/javascript" charset="utf-8">
        mui.init();
    </script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cb5d49b07e0a753dc8ee27ba2c73495d";
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(hm, s);
})();
</script>
</head>

<body>
    <div class="container" style="padding:0px;">
        <div class="navbar">
            <div class="backBtn">
                <span class="mui-icon mui-icon-arrowleft" onclick="javascript:history.back(-1);"></span>
            </div>
            <span><?php echo $order[0]['u_name'] ?></span>
        </div>
        <div class="orderDetail">
            <div class="orderInfo">
                <div class="imgBox"><img src="<?php echo $goods[0]['img'] ?>" alt=""></div>
                <div class="right">
                    <div class="name"><?php echo $goods[0]['title'] ?>    *<?php echo $order[0]['number']?> </div>
                    <span class="price"><span>¥</span><?php echo $goods[0]['money'] ?></span>
                    <span class="now_price"><span>¥</span><?php echo $goods[0]['money'] ?></span>
                </div>
            </div>
        </div>

        <?php if($goods[0]['is_give']){?>
            <img src="<?php echo $goods[0]['img'] ?>" style="width:calc(100% - 16px);height: 60px;margin: 8px">
        <?php } ?>
        <!-- <div class="extraInfo">
            <div class="title">退款成功（1张）</div>
            <div class="label">
                <span>有效期至2020-06-13</span>
                <span id="red">查看退款详情
                    <span class="mui-icon  mui-icon-forward tuikuan_arrow"></span>
                </span>
            </div>
            <div class="quanhao">
                券号：3333 5555 87
            </div>


        </div>
        <div class="extraInfo">
            <div class="title tuangou">团购详情</div>
            <div class="tg_detal">
                <div class="tg_name">焦糖玛奇朵大杯</div>
                <div class="tg_price">
                    <span>1</span>
                    <span>85元</span>
                </div>
            </div>
            <div class="tg_total">
                <span>总价</span>
                <span>85元</span>
            </div>
            <div class="tg_tuangoutotal">
                <span>总价</span>
                <span>75元</span>
            </div>


        </div> -->
        <div class="extraInfo">
            <div class="title tuangou">温馨提示</div>
            <div class="tip_start">
                <span class="tip_start_left">
                    <div>有效期</div>
                    <div class="black"><?php echo date('Y-m-d',$order[0]['start_time']) ?>至<?php echo date('Y-m-d',$order[0]['end_time']) ?></div>
                </span>
                <span class="tip_start_right">
                    <div>使用时间</div>
                    <div class="black">10：00-21：00</div>
                </span>
            </div>


        </div>
        <div class="extraInfo">
            <?php if($order[0]['youji'] == 'youji'){ ?>

                <?php switch ($order[0]['state']) { case 0:?>
                    <div class="title tuangou">订单状态</div>
                    <div class="erweima">订单未付款</div>
                <?php break;case 1: ?>
                    <div class="title tuangou">订单状态</div>
                    <?php if($type == 'shop'){ ?>
                        <div class="delivery" data_num="<?php echo $order[0]['ordernum'] ?>" style="    width: 200px;display: inline-block;line-height: 40px;text-align: center;background: #c8c7cc;border-radius: 5px;color: #333;font-size: 14px;position: relative;left: 50%;transform: translateX(-50%);margin-top: 30px;">确认发货</div>
                    <?php }elseif($type == 'user'){ ?>
                        <div class="erweima">商家派送中</div>
                    <?php } ?>
                <?php break;case 3: ?>
                    <div class="title tuangou">订单状态</div>
                    <div class="erweima">订单已发货</div>
                <?php break;case 4: ?>
                    <div class="title tuangou">订单状态</div>
                    <div class="erweima">订单已过期</div>
                <?php break;case 5: ?>
                    <div class="title tuangou">订单状态</div>
                    <div class="erweima">订单退款已发起</div>
                <?php break;case 6: ?>
                    <div class="title tuangou">订单状态</div>
                    <div class="erweima">订单退款已通过</div>
                <?php break;case 7: ?>
                    <div class="title tuangou">订单状态</div>
                    <div class="erweima">订单退款已驳回</div>
                <?php break;} ?>
            <?php }else{ ?>
                <?php switch ($order[0]['state']) { case 0:?>
                    <div class="title tuangou">订单状态</div>
                    <div class="erweima">订单未付款</div>
                <?php break;case 1: ?>
                    <div class="title tuangou">二维码核销</div>
                    <div class="erweima">
                        <img style="width:70%;" src="<?php echo $order[0]['hexiao_qr'] ?>" alt="">
                    </div>
                <?php break;case 2: ?>
                    <div class="title tuangou">二维码核销</div>
                    <div class="erweima">
                        <img style="width:70%;" src="<?php echo $order[0]['hexiao_qr'] ?>" alt="">
                    </div>
                <?php break;case 3: ?>
                    <div class="title tuangou">订单状态</div>
                    <div class="erweima">订单已核销</div>
                <?php break;case 4: ?>
                    <div class="title tuangou">订单状态</div>
                    <div class="erweima">订单已过期</div>
                <?php break;case 5: ?>
                    <div class="title tuangou">订单状态</div>
                    <div class="erweima">订单退款已发起</div>
                <?php break;case 6: ?>
                    <div class="title tuangou">订单状态</div>
                    <div class="erweima">订单退款已通过</div>
                <?php break;case 7: ?>
                    <div class="title tuangou">订单状态</div>
                    <div class="erweima">订单退款已驳回</div>
                <?php break;} ?>
            <?php } ?>
        </div>
        <div class="extraInfo">
            <div class="title tuangou">订单信息</div>
            <div class="order_num">
                <span>联系电话：</span>
                <span><?php echo $order[0]['mobile']; ?></span>
            </div>
            <div class="order_num">
                <span>订单编号：</span>
                <span><?php echo $order[0]['ordernum'] ?></span>
            </div>
            <div class="order_time">
                <span>下单时间：</span>
                <span><?php date('Y-m-d',$order[0]['start_time']) ?></span>
            </div>
            <div style="display: flex;align-items: center;justify-content: space-between;">
                <div>
                    <div class="order_total">
                        <span>订单总价：</span>
                        <span>￥ <?php echo $order[0]['money'] ?>  </span>
                    </div>
                    <div class="order_total">
                        <span>实际付款：</span>
                        <span class="red">￥<?php echo $order[0]['money'] ?></span>
                    </div>
                </div>
                <?php if( ($order[0]['state'] == 1 || $order[0]['state'] == 2) && ($order[0]['uptime'] == '' ) && $type == 'user'){ ?>
                    <div style="font-size: 14px;color: #999;" onclick="goTuiKuan()">申请退款</div>
                <?php } ?>
            </div>
        </div>

        <?php if($order[0]['youji'] == 'youji' || $order[0]['link_man'] || $order[0]['link_address']){?>
            <div class="extraInfo">
                <div class="mendian">邮寄信息</div>
                <div class="" style="margin-top: 10px;">
                    <p>联系人：<?php echo $order[0]['link_man'] ?></p>
                    <p>联系电话：<?php echo $order[0]['mobile'] ?></p>
                    <p>收货地址：<?php echo $order[0]['link_address'] ?></p>
                </div>
            </div>
        <?php }?>

        <div class="extraInfo">
            <div class="mendian">门店信息</div>
            <div class="mendian_address">
                <span><?php echo $shop[0]['username'] ?>
                </span>
                <span class="red shop_add"></span>
            </div>
            <div>
                <span class="mui-icon mui-icon-location mendian_address_icon"><?php echo $shop[0]['shop_add'] ?>
                </span>
            </div>
        </div>

    </div>

</body>
<script src="js/jquery-2.2.4.min.js"></script>
<script src="js/qrcode.min.js"></script>
<script src="js/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="//webapi.amap.com/maps?v=1.4.1&key=fedad41056b27c3e8cc5eaca216434e9"></script>
<script>
    $(".delivery").click(function(){
        var data_num = $(this).attr("data_num");
        $.ajax({
            url : 'order_delivery_ajax.php',
            data : {'data_num':data_num},
            type : 'post',
            dataType : 'json',
            success : function(ret){
                if(ret.code == 'Y'){
                    alert(ret.info);
                    window.location.reload();
                }else if (ret.code == 'N') {
                    alert(ret.info);
                }else{
                    alert('请联系管理员');
                }
            }
        })
    })
    function goTuiKuan() {
        location.href = './tuikuan.php?order_id=<?php echo $id; ?>'
    }
    $(function(){
        //获取当前位置信息
        function getaddre(){
            var x = "<?php echo $shop[0]['shop_lat']; ?>";
            var y = "<?php echo $shop[0]['shop_lng']; ?>";

            var map, geolocation;
            map = new AMap.Map('allmap');
            map.plugin('AMap.Geolocation', function() {
                geolocation = new AMap.Geolocation({
                    enableHighAccuracy: true //是否使用高精度定位，默认:true
                });
                geolocation.getCurrentPosition();
                AMap.event.addListener(geolocation, 'complete', function(point){

                    var lnglatXY = y+","+x; //已知点坐标
                    console.log(lnglatXY);
                    map.plugin('AMap.Geocoder', function() {
                        var geocoder = new AMap.Geocoder();
                        geocoder.getAddress(lnglatXY, function(status, result) {
                            if (status === 'complete' && result.info === 'OK') {
                                var address = result.regeocode.formattedAddress;
                                var obj = result.regeocode.addressComponent;
                                address = address.replace(obj.province, '');
                                address = address.replace(obj.district, '');
                                address = address.replace(obj.city, '');
                                var lng = point.position.lng;
                                var lat = point.position.lat;
                                var p1 = [y,x];
                                var p2 = [point.position.lng,point.position.lat];
                                var dis = AMap.GeometryUtil.distance(p1, p2);
                                var danwei;
                                if(dis > 1000){
                                    dis = dis / 1000;
                                    dis = Math.round(dis);
                                    danwei = 'KM';
                                }else{
                                    dis = Math.round(dis);
                                    danwei = 'M';
                                }
                                $("#address").html(address);
                                $(".shop_add").html(dis + danwei);
                                console.log(address);
                                $("input[name='lng']").attr('value', point.position.lng);
                                $("input[name='lat']").attr('value', point.position.lat);
                                console.log(point.position.lng,point.position.lat);
                            }
                        });
                    });
                });
            });

        }
        getaddre();
    })
</script>

</html>
